﻿Public Class clsPgdMes

    Public Function insert(en As entityPgdMes) As Integer
        Dim szSql As String = String.Empty
        Dim rtn As Integer
        szSql &= "INSERT INTO sf.b_pgd_mes(oper_date, mes_project_code, mes_project_name, support_model, type_value, oper_count, note, workshop_id, validity, status, origin, operator, update_time, jp_type, pgd_code) "
        szSql &= "VALUES ( ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? ,? , (SELECT CURRENT_TIMESTAMP(6)),?,?); "
        rtn = DBacs.ExecuteUpdateSql(szSql, -1, en.oper_date, en.mes_project_code, en.mes_project_name, en.support_model, en.type_value, en.oper_count, en.note, en.workshop_id, en.validity, en.status, en.origin, en.Ope, en.jp_type, en.pgd_code)
        Return rtn
    End Function

    Public Function update(en As entityPgdMes) As Integer
        Dim szSql As String = String.Empty
        Dim rtn As Integer
        szSql &= "update sf.b_pgd_mes set oper_date = ?, mes_project_code = ?, mes_project_name = ?, support_model = ? , type_value = ?, oper_count = ?, note = ?, workshop_id = ?, validity = ?, status = ? , origin = ?, operator = ?, update_time = (SELECT CURRENT_TIMESTAMP(6)) "
        szSql &= " where pgd_code = ? "
        rtn = DBacs.ExecuteUpdateSql(szSql, -1, en.oper_date, en.mes_project_code, en.mes_project_name, en.support_model, en.type_value, en.oper_count, en.note, en.workshop_id, en.validity, en.status, en.origin, en.Ope, en.pgd_code)
        Return rtn
    End Function

    Public Function getPgd(workshop_id As Integer, startTime As String, endTime As String) As DataTable
        Dim szSql As String = ""
        szSql &= "SELECT a.*,b.jp_layer_num,b.mould_no,b.prod_spec_name,c.type,c.spec,c.model FROM sf.b_pgd_mes a "
        szSql &= " left join sf.t_prod_spec b on a.support_model = b.prod_spec_id "
        szSql &= " left join sf.t_mst_jp c on a.type_value = c.material_code "
        szSql &= " where 1 = 1 and a.workshop_id = ?"
        If startTime <> "" Then
            szSql &= "  and a.oper_date >= ?"
        End If
        If endTime <> "" Then
            szSql &= "  and a.oper_date <= ?"
        End If
        szSql &= "  ORDER BY a.oper_date ASC"
        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1, workshop_id, startTime, endTime)
        Return dt
    End Function

    Public Function getListBySysId(sys_id As String) As DataTable
        Dim szSql As String = "SELECT * FROM sf.b_pgd_mes where sys_id = ? "
        Return DBacs.ExecuteSql(szSql, -1, sys_id)
    End Function

    Public Function getListByPgd(pgd_code As String) As DataTable
        Dim szSql As String = ""
        szSql &= "SELECT * FROM sf.b_pgd_mes where 1 = 1 and pgd_code = ? "
        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1, pgd_code)
        Return dt
    End Function
End Class
